{extend name="common/base" /}

{block name="body"} 
<div class="head_box">
    <i class="layui-icon layui-icon-left" onclick="back()"></i>
    <div class="t1">计划</div>
 </div>
 <main class="main_body">
    <div class="title_nav">
        {if $role && $role.is_admin == 1} 
             <a href="plan_add.html">添加计划</a>       
            <a class="active" href="plan_list.html">管理计划</a>
        {/if}

       <a href="plan_today.html">今日计划</a>
    </div>
    <div class="plan_ul">
       <div class="d-flex al-c jc-fe ftc">
          <span id="car_btn">选择车型</span>
          <i class="layui-icon layui-icon-right"></i>
       </div>

       {volist name="list" id="vo"} 
            <div class="plan_item">
                <div class="b1">
                <div class="time_box">
                    <img class="date" src="__ROOT__/static/images/date.png">
                    <span>{$vo.start_time|strtotime|date="Y-m-d H:i"}</span>
                </div>
                <div>
                    <span class="type1 type">{$vo.status_text}</span>
                    <i class="layui-icon layui-icon-right"></i>
                </div>
                </div>
                <div class="b2">
                <div>工作描述：{$vo.crane.name}-{$vo.segment.name}-{$vo.stage.name}</div>
                <div>实际完成时间：{$vo.complete_time}</div>
                <div>备注：{$vo.remarks}</div>
                </div>
                <div class="b3">
                <a href="/plan_edit/{$vo.id}" class="layui-btn btn-border">修改</a>
                <button class="layui-btn btn-delete delete_plan" data-id="{$vo.id}">删除</button>
                </div>
            </div>
       {/volist}
       
   
    </div>

 </main>
 <div class="list_footer">
    <a class="item">
       <button class="layui-btn w100 add_plan">添加</button>
    </a>
    <!-- <a class="item">
       <button class="layui-btn btn-border w100">调整计划</button>
    </a> -->
 </div>
 <div class="car_change" id="car_change">
    <div class="car" style="width: 75%;">
        <div class="car_name">
            <label>选择车型</label>
            <select name="car_id" id="carSelect">
                   <option value="0">全部</option>
                {volist name="carne_list" id="vo"}
                    <option {if $car_id == $vo.id} selected {/if} value="{$vo.id}">{$vo.name}</option>
                {/volist}
            </select>
        </div>
        <div class="car_button">
            <button id="closebtn" type="button">关闭</button>
            <button type="button" id="submitbtn" class="select_car">提交</button>
        </div>
    </div>
 </div>
{/block}
{block name="js"}
<script>
 function back(){
      window.location.href="/index"
    }
layui.use(['form', 'laydate', 'util'], function () {
      var form = layui.form;
      var layer = layui.layer;
      var laydate = layui.laydate;
      var util = layui.util;

      // 日期
      laydate.render({
         elem: '#date'
      }); laydate.render({
         elem: '#date1'
      });
      $("#car_btn").on("click",function(){
        $('.car_change').show();
        })
        $("#closebtn").on("click",function(){
            $('.car_change').hide();
        })
         // 关闭按钮点击事件
    $('#closebtn').click(function() {
        $('#car_change').hide();  // 隐藏 div
    });

    $('.delete_plan').click(function(){
        var id = $(this).data('id');
        layer.confirm('确认删除么？', {
            btn: ['确定', '取消'] // 按钮
        }, function() {
            ajaxRequest('/plan_delete', {id : id}, 'POST', this, function (response) {
                layer.msg('操作成功', {icon: 1, time: 1000}, function() {
                    window.location.reload();
                });
            });
        }, function() {
         
        });
    })

    // 提交按钮点击事件
    $('#submitbtn').click(function() {
        // 获取 select 选择的车型 ID
        var carId = $('#carSelect').val();
        
        // 检查是否选择了车型
        if (carId === '') {
            layer.msg('请选择车型');
            return;
        }

        var currentUrl = window.location.href;
        // 创建一个 URL 对象
        var url = new URL(currentUrl);
        
        // 更新 car_id 参数
        url.searchParams.set('car_id', carId);
        
        // 重定向到新的 URL，刷新页面
        window.location.href = url.toString();
    });

    $('.add_plan').click(function(){
        window.location.href = '/plan_add';
    })
});
 </script>
{/block}

